import time

from selenium.webdriver.common.by import By

from common.Utils import forum


class register:
    url=""
    driver = ""
    def __init__(self):
        self.url = "http://127.0.0.1:58080/sign-up.html"
        self.driver = forum.driver
        self.driver.get(self.url)

    #正常注册
    def ResgisterSuc(self):
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("test")
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("test")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("123456")
        # 同意条框点击注册
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        time.sleep(1)
        # 进行截图
        forum.GetScreenShot()
        #验证成功后是否跳转到登录页面
        self.driver.find_element(By.CSS_SELECTOR,"body > div > div > div > div:nth-child(1) > div > div.card.card-md > div > h2")
    #异常注册
    def ResgisterFail(self):
        #测试用例：不输入用户名，但输入昵称、密码，同意条款进行注册
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("测试员")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("123")
        # 同意条框点击注册
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        time.sleep(1)
        # 进行截图
        forum.getscreenshot()
        # 寻找用户名不能为空的提示内容验证测试结果
        self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(2) > div")

